package com.botu.springcloudsentineldatasource.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.botu.springcloudsentineldatasource.common.utils.FallbackExUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Author: hanzeyao
 * @Date: 2019/12/12 10:54
 * @Description:
 */
@Service
@Slf4j
public class TestService {

    @SentinelResource(value = "demo",fallback = "fallback")
    public String demo(){
        return "==pass==";
    }

    public String fallback(){
        return "==flow==";
    }

    @SentinelResource(value = "flow",fallback = "demo2",fallbackClass = FallbackExUtils.class)
    public String demo2() {
        return "==sentnel pass==";
    }

    @SentinelResource(value = "degrade",fallback = "degrade1")
    public String degrade() {
        try {
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "==pass==";
    }

    public String degrade1() {
        return "==degrade==";
    }
}
